﻿//-----------------------------------------------------------------------
//  This file is part of the Microsoft Code Samples.
// 
//  Copyright (C) Microsoft Corporation.  All rights reserved.
// 
//  This source code is intended only as a supplement to Microsoft
//  Development Tools and/or on-line documentation.  See these other
//  materials for detailed information regarding Microsoft code samples.
// 
//  THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//-----------------------------------------------------------------------

#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

namespace RetailAnalytic.Tools.ActivitySystem
{
    public static class MonitoredItems
    {
        private static List<MonitoredItem> cancelledItems = new List<MonitoredItem>();

        public enum MonitoredItemType { Connection = 0, Session };
        public enum MonitoredItemAction { Cancel = 0 };

        public static void Add(MonitoredItem item)
        {
            if (!Utilities.IsLoggingEnabled)
                return;

            lock (cancelledItems)
            {
                if (cancelledItems.Contains(item))
                    return;
                
                cancelledItems.Add(item);
            }
        }
        
        public static void Remove(MonitoredItem item)
        {
            lock (cancelledItems)
            {
                cancelledItems.Remove(item);
            }
        }

        public static void Clear()
        {
            lock (cancelledItems)
            {
                cancelledItems.Clear();
            }
        }
        
        public static int Count
        {
            get
            {
                lock (cancelledItems)
                {
                    return cancelledItems.Count;
                }
            }
        }

        public static MonitoredItem Item(int index)
        {
            lock (cancelledItems)
            {
                return cancelledItems[index];
            }
        }
    }
}
